﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**
*@file       msgprocdispathcer.cs
*@brief      helper class for message process
*
*@author     graywind
*@version    1.0.0.0
*@data       2011/12/30
*/
//default dispatcher
public class NetOperateTypeDispatcher<Operator, type> where type : NetCommon.OperateType
{
    public static void OnDispatch(Operator p, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code)
    {

    }
}

//implement OnDispatch function by user
public partial class NetOperateListenDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateListen>
{

}
//implement OnDispatch function by user
public partial class NetOperateConnectDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateConnect>
{

}
//implement OnDispatch function by user
public partial class NetOperateKickDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateKick>
{

}
//implement OnDispatch function by user
public partial class NetOperateDisconnectDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateDisconnect>
{

}
//implement OnDispatch function by user
public partial class NetOperateSendDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateSend>
{

}
//implement OnDispatch function by user
public partial class NetOperateReadDispatcher<Operator> : NetOperateTypeDispatcher<Operator, NetCommon.OperateRead>
{

}

//static function pointer holder
class NetDispatcherFuncPtr<Operator>
{
    private const int MAX_OPERATE = 6;

    public delegate void MsgProcDispatchFunc(Operator p, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code);

    public static MsgProcDispatchFunc[] FuncPtrArray = new MsgProcDispatchFunc[MAX_OPERATE] { 
                                                                                              NetOperateListenDispatcher<Operator>.OnDispatch,  
                                                                                              NetOperateConnectDispatcher<Operator>.OnDispatch,
                                                                                              NetOperateKickDispatcher<Operator>.OnDispatch,
                                                                                              NetOperateDisconnectDispatcher<Operator>.OnDispatch,
                                                                                              NetOperateSendDispatcher<Operator>.OnDispatch,
                                                                                              NetOperateReadDispatcher<Operator>.OnDispatch,
                                                                                            };
}

//message dispathcer
class NetMsgProcDispatcher
{
    public static void dipatch<Operator>(Operator p, Int32 type, Int32 session_id, IntPtr pMsgBuffer, UInt32 msgId, UInt32 msg_bytes, Int32 error_code)
    {
        NetDispatcherFuncPtr<Operator>.FuncPtrArray[type](p, session_id, pMsgBuffer, msgId, msg_bytes, error_code);
    }
}